﻿<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<body>
    <h>在线编辑: </h>
    <blockquote>
        <input type="button" value="1.doc" onclick="openFile('1.doc')" />
        <input type="button" value="2.xls" onclick="openFile('2.xls')" />
        <input type="button" value="3.ppt" onclick="openFile('3.ppt')" />
        <input type="button" value="预览" onclick="preView('1.doc')" />
        <input type="button" value="新建" onclick="newFile()" />
    </blockquote>
</body>
<script src="https://qn.cache.wpscdn.cn/js/jquery-1.9.1.min.js"></script>
<script src="Resource/JavaScript/wps/jwps.js"></script>
<script>
     function newFile() {
        $.ajax({
           // url: "/Oauth/GetAppToken?filename=" + filename,  
             url: "/weboffice/new",  
            type: "get",
            async: false,
            cache: false,
            dataType: "json",
            //data: {
            //    "filename": filename
            //},
            success: function (r) {  
               console.log(r);
                wps = WPS.config({wpsUrl: r.redirect_url});
              //  wps.setToken({token: r.user_id});
            },
            error: function (err) {    //url无效，请求失败；有Exception异常，没有捕获时。
                alert(err);
            }
        });
    }
     function preView(filename) {
        $.ajax({
           // url: "/Oauth/GetAppToken?filename=" + filename,  
             url: "/weboffice/url",  
            type: "get",
            async: false,
            cache: false,
            dataType: "json",
            data: {
                "filename": filename,
                "file_permission":"read"
            },
            success: function (r) {  
               console.log(r);
                wps = WPS.config({wpsUrl: r.Url});
                wps.setToken({token: r.Token});
            },
            error: function (err) {    //url无效，请求失败；有Exception异常，没有捕获时。
                alert(err);
            }
        });
    }

    function openFile(filename) {
        $.ajax({
           // url: "/Oauth/GetAppToken?filename=" + filename,  
             url: "/weboffice/url",  
            type: "get",
            async: false,
            cache: false,
            dataType: "json",
            data: {
                "filename": filename
            },
            success: function (r) {  
               console.log(r);
                wps = WPS.config({wpsUrl: r.Url});
                wps.setToken({token: r.Token});
            },
            error: function (err) {    //url无效，请求失败；有Exception异常，没有捕获时。
                alert(err);
            }
        });
    }
</script>
<style>
    * {
        box-sizing: border-box;
    }

    html,
    body {
        display: flex;
        flex-direction: column;
        padding: 0;
        margin: 0;
        height: 100%;
        /* 防止双击缩放 */
        touch-action: manipulation;
    }

    iframe {
        flex: 1;
    }
</style>
</html> 